# -*- coding:utf-8 -*-

import werkzeug.urls

from odoo import fields

from odoo import http
from odoo.http import request
from odoo.addons.website.models.website import unslug
from odoo.tools.translate import _

import logging
_logger = logging.getLogger(__name__)

class WebsiteMemberDetail(http.Controller):

    @http.route(['/memberdetail/<member_no>'], type='http', auth="public", website=True)
    def partners_detail(self, member_no, **post):
        # James add debug:
        _logger.info("\njames Debug,member_no="+member_no)
        
        MembershipLine = request.env['membership.membership_line']

        _, member_no = unslug(member_no)
        if member_no:
            MembershipLine = request.env['membership.membership_line']
            partner_id = MembershipLine.get_member(member_no=member_no)
            partner = request.env['res.partner'].sudo().browse(partner_id)
            if partner.exists():  # TODO should be done with access rules
                values = {}
                values['main_object'] = values['partner'] = partner
                return request.render("website_member_detail.partner_member_detail", values)
        else:
            return request.render("website_member_detail.partner_member_notfound",{})